<%@ page import="custom.*, java.util.*, java.sql.*, javax.sql.*, javax.naming.*" %>
<%
String degreeLoc = request.getParameter("degreeLoc");
String univ = request.getParameter("univ");
// System.out.println(degreeLoc+", "+univ);
int valid=1;
try {
    InitialContext cxt = new InitialContext();
    DataSource ds = (DataSource) cxt.lookup("java:/comp/env/jdbc/postgres");
    Connection conn = ds.getConnection();
    // compare the university names (case insensitive) to test duplicates
    PreparedStatement pstmt = conn.prepareStatement("select * from universities where country_state=? and lower(university)=lower(?)");
    pstmt.setString(1, degreeLoc);
    pstmt.setString(2, univ);
    ResultSet rs = pstmt.executeQuery();
    while(rs.next()) {
        valid=0; // if there is any result, it means a duplicate
    }
    pstmt.close();
    conn.close();
}
catch(Exception e) {
}
%>
<%=valid%>